﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace ElectricBillMaker
{
    class Controller
    {
        private Model model_;
        private IView view_;

        public Controller( Model model, IView view )
        {
            model_ = model;
            view_ = view;
        }

        public void OnChange()
        {
            //
            // TODO: move deltas calculation to model
            //

            view_.OnDeltaChanged(view_.GetCurCounter1() - view_.GetPrevCounter1(),
                            view_.GetCurCounter2() - view_.GetPrevCounter2(),
                            view_.GetCurCounter3() - view_.GetPrevCounter3());

            model_.Delta1 = view_.GetDelta1();
            model_.Delta2 = view_.GetDelta2();
            model_.Delta3 = view_.GetDelta3();

            model_.Tarif1 = view_.GetTarif1();
            model_.Tarif2 = view_.GetTarif2();
            model_.Tarif3 = view_.GetTarif3();

            model_.PrivilegeKw = view_.GetPrivilegeKw();
            model_.PrivilegePercent = view_.GetPrivilegePercent();
        }

        public void OnCalculate()
        {
            OnChange();
            SetRegistrations();
            model_.Calculate();
        }

        public void OnBill()
        {
            model_.OnBill();
        }

        public void OnMonthChange()
        {
            UpdateMonthYear();
        }

        public void OnYearChange()
        {
            UpdateMonthYear();
        }

        public void OnNewCalc()
        {
            
        }


        private void UpdateMonthYear()
        {
            model_.MonthYear = new DateTime(view_.GetYear(), view_.GetMonth(), 1);
        }

        private void SetRegistrations()
        {
            model_.Registration1 = view_.GetCurCounter1();
            model_.Registration2 = view_.GetCurCounter2();
            model_.Registration3 = view_.GetCurCounter3();
        }
            
    }
}
